﻿@{
    ViewBag.Title = "列表页面";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>;
    $(function () {
        InitialPage();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //resize重设布局;
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $('#gridTable').setGridHeight($(window).height() - 136.5);
            }, 200);
            e.stopPropagation();
        });
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            autowidth: true,
            height: $(window).height() - 136.5,
            url: "../../SystemManage/DataSource/GetPageListJson",
            datatype: "json",
            colModel: [
                { label: '数据源主键', name: 'Id', index: 'Id', width: 100, align: 'left',sortable: true ,hidden: true },
                { label: '数据名称', name: 'Name', index: 'Name', width: 100, align: 'left', sortable: true },
                 { label: '数据编号', name: 'Code', index: 'Code', width: 100, align: 'left', sortable: true },
                { label: '数据库名', name: 'DbName', index: 'DbName', width: 100, align: 'left',sortable: true  },
                { label: '创建人', name: 'CreateUserName', index: 'CreateUserName', width: 100, align: 'left',sortable: true  },
                { label: '创建时间', name: 'CreateDate', index: 'CreateDate', width: 100, align: 'left', sortable: true },
                 { label: "备注", name: "Description", index: "Description", width: 200, align: "left" }

            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'CreateDate',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $('#' + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $('#' + this.id).setSelection(selectedRowIndex, false);
            }
        });
    }
    //新增
    function btn_add() {
        dialogOpen({
            id: 'Form',
            title: '添加数据源',
            url: '/SystemManage/DataSource/Form',
            width: '650px',
            height: '450px',
            btn: null,
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }
    //编辑
    function btn_edit() {
        var keyValue = $('#gridTable').jqGridRowValue('Id');
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: 'Form',
                title: '编辑数据源',
                url: '/SystemManage/DataSource/Form?keyValue=' + keyValue,
                width: '650px',
                height: '450px',
                btn: null,
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            })
        }
    }
    function btn_preview() {
        var keyValue = $("#gridTable").jqGridRowValue("F_Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑数据源',
                url: '/SystemManage/DataSource/PreviewForm?keyValue=' + keyValue,
                width: "650px",
                height: "500px",
                btn: null,
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }

    //删除
    function btn_delete() {
        var keyValue = $('#gridTable').jqGridRowValue('Id');
        if (keyValue) {
            $.RemoveForm({
                url: '../../SystemManage/DataSource/RemoveForm',
                param: { keyValue: keyValue },
                success: function (data) {
                    $('#gridTable').trigger('reloadGrid');
                }
            })
        } else {
            dialogMsg('请选择需要删除的数据源表！', 0);
        }
    }
</script>
<div class="titlePanel">
    <div class="toolbar">
        <div class="btn-group">
            <a id="lr-replace" class="btn btn-default" onclick="reload()"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
            <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
            <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
            @*<a id="lr-preview" class="btn btn-default" onclick="btn_preview()"><i class="fa fa-eye"></i>&nbsp;测试</a>*@
            <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
        </div>
    </div>
</div>
<div class="gridPanel">
    <table id="gridTable"></table>
    <div id="gridPager"></div>
</div>
